<template>
	<view class="costom-tabs">
		<view class="tab" :style="{fontSize: fontS}" v-for="(item, index) in tabs" @click="handleTabClick(index)">
			<template v-if="tabType === 'text'">
				<view class="text" :class="{ active: currIdx == index}">{{item}}</view>
			</template>
			<template v-else-if="tabType === 'costom'">
				<slot name="tab" :data="{item, index}"></slot>
			</template>
		</view>
	</view>
</template>

<script>
	export default {
		/**
		 * dropdown 自定义Tap
		 * @description 该组件一般用于Tap
		 * @property {Array} data  必传项 tab的展示数据
		 * @property {String} size Tap 的文字大小 默认为30rpx
		 * @property {String} type Tap 的类型 展示默认 一般为 text文本 也可以传入costom 插槽类型自定义
		 * @property {Function} onTap Tap点击的方法
		 * @example <Tap></Tap>
		 */
		data() {
			return {
				tabs: [],
				currIdx: 0,
				fontS: '30rpx',
				tabType: 'text'
			}
		},
		props: {
			data: {
				type: Array,
				default: []
			},
			size: {
				type: String,
				default: '30rpx'
			},
			type: {
				type: String,
				default: 'text'
			}
		},
		created() {
			const {
				data,
				size,
				type
			} = this.$props
			console.log(data);
			if (data) this.tabs = data
			if (type) this.tabType = type
			this.fontS = size
		},
		mounted() {

		},
		methods: {
			handleTabClick(idx) {
				this.currIdx = idx
				this.$emit('onTap', idx)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.costom-tabs {
		display: flex;
		align-items: center;

		.tab {
			flex: 1;
			display: flex;
			align-items: center;
			justify-content: center;

			.text {
				color: #333;
				padding-bottom: 8rpx;
			}
		}

		.active {
			color: #D0241C !important;
			border-bottom: 6rpx solid #D0241C;
		}
	}
</style>